package com.uinnova.springboot.demo.application.listener;

import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 张攀钦
 * @date 2018/12/21-10:27
 * 事件监听
 */
@Component
public class ContextRefreshedListener implements ApplicationListener<ContextRefreshedEvent> {


    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        // 根容器为Spring容器  
        if (event.getApplicationContext().getParent() == null) {
            Map<String, Object> beans = event.getApplicationContext().getBeansWithAnnotation(RestController.class);
            for (Object bean : beans.values()) {
                System.err.println(bean == null ? "null" : bean.getClass().getName());
            }
        }
    }
}